package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.DataDictionaryItem;
import cn.wolfcode.crm.query.DataDictionaryItemQueryObject;
import cn.wolfcode.crm.service.IDataDictionaryItemService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("dataDictionaryItem")
public class DataDictionaryItemController {

    @Autowired
    private IDataDictionaryItemService service;

    /**
     * 获取会员等级信息
     */
    @RequestMapping("getItem")
    @ResponseBody
    public List<DataDictionaryItem> getItem(String sn) {
        return service.getItemByDictionarySn(sn);
    }

    @ResponseBody
    @RequestMapping("list")
    public PageResult list(DataDictionaryItemQueryObject qo) {
        return service.query(qo);
    }

    @RequestMapping("save")
    @ResponseBody
    public JsonResult save(DataDictionaryItem entity) {
        JsonResult result = new JsonResult();
        try {
            service.save(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("保存操作失败");
        }
        return result;
    }

    @RequestMapping("update")
    @ResponseBody
    public JsonResult update(DataDictionaryItem entity) {
        JsonResult result = new JsonResult();
        try {
            service.update(entity);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("编辑操作失败");
        }
        return result;
    }

    @RequestMapping("delete")
    @ResponseBody
    public JsonResult delete(Long id) {
        JsonResult result = new JsonResult();
        try {
            service.delete(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("编辑操作失败");
        }
        return result;
    }

}
